var t = getApp();

Page({
    data: {
        clause: [],
        clauselist: [],
        title: "",
        parties: "",
        ht: {},
        url: "",
        url2: "",
        id: "",
        sessin: "",
        img: "../../images/12.png",
        condition: !0,
        netbol: !0,
        canIu: !1,
        btnbol: !0
    },
    onLoad: function(a) {
        wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        });
        var e = this, i = a.id, o = a.url, n = a.url2, s = a.sessin;
        this.setData({
            url: o,
            url2: n,
            id: i,
            sessin: s,
            Listurl: a.Listurl,
            TopName: a.TopName
        });
        t.globalData.htGet;
        wx.request({
            url: t.url + "addon/" + o,
            data: {
                id: i
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                t.globalData.htGet = a.data;
                var i = a.data.obliga, o = a.data.obligb, n = a.data.obligc, s = a.data.end;
                i && i.length > 0 && (t.globalData.htGet.obliga = i.split("【&#下一条：^//////】"), i = i.split("【&#下一条：^//////】")), 
                o && o.length > 0 && (t.globalData.htGet.obligb = o.split("【&#下一条：^//////】"), o = o.split("【&#下一条：^//////】")), 
                s && s.length > 0 && (t.globalData.htGet.end = s.split("【&#下一条：^//////】"), s = s.split("【&#下一条：^//////】")), 
                n && n.length > 0 && (t.globalData.htGet.obligc = n.split("【&#下一条：^//////】"), n = n.split("【&#下一条：^//////】")), 
                e.setData({
                    ht: t.globalData.htGet
                });
                var l = [ {
                    keyword: "交易概述",
                    keyname: "summary",
                    text: a.data.summary
                }, {
                    keyword: "甲方义务",
                    keyname: "obliga",
                    text: i
                }, {
                    keyword: "乙方义务",
                    keyname: "obligb",
                    text: o
                }, {
                    keyword: "丙方义务",
                    keyname: "obligc",
                    text: n
                }, {
                    keyword: "验收条款",
                    keyname: "accept",
                    text: a.data.accept
                }, {
                    keyword: "违约责任",
                    keyname: "liabity",
                    text: a.data.liabity
                }, {
                    keyword: "免责事由",
                    keyname: "execept",
                    text: a.data.execept
                }, {
                    keyword: "争议解决",
                    keyname: "dispute",
                    text: a.data.dispute
                }, {
                    keyword: "其他条款",
                    keyname: "end",
                    text: s
                } ];
                l.slice(1, 4).filter(function(t) {
                    return t.text && t.text.length > 0;
                });
                l[1].text && l[1].text.length > 0 && (l[1].text = l[1].text.map(function(t) {
                    return l[1].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join("")), l[2].text && l[2].text.length > 0 && (l[2].text = l[2].text.map(function(t) {
                    return l[2].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join("")), l[3].text && l[3].text.length > 0 && (l[3].text = l[3].text.map(function(t) {
                    return l[3].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join("")), void 0 !== l[8].text && null !== l[8].text && l[8].text.length > 0 && (l[8].text = l[8].text.map(function(t) {
                    return l[8].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join(""));
                for (var r = l.filter(function(t) {
                    return void 0 !== t.text && null !== t.text && t.text.length > 0;
                }), d = [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" ], c = 0, u = r.length; c < u; c++) r[c].inDex = d[c];
                e.setData({
                    clause: l,
                    clauselist: r,
                    btnbol: !1
                }), wx.hideToast();
            },
            fail: function(t) {
                wx.hideToast(), e.setData({
                    netbol: !1
                }), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2200
                });
            }
        }), 1 == wx.canIUse("button.open-type.share") && this.setData({
            canIu: !0
        });
    },
    toEdit: function() {
        var a = this.data.id, e = this.data.url, i = this.data.sessin, o = this.data.ht;
        t.globalData.OrihtGet = o, t.globalData.OrihtGet.url = e, t.globalData.OrihtGet.sessin = i, 
        wx.redirectTo({
            url: "../MyShtedit/MyShtedit?id=" + a + "&url=" + e + "&sessin=" + i + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName
        });
    },
    noEdit: function() {
        var t = this.data.id, a = this.data.url, e = this.data.sessin;
        wx.navigateTo({
            url: "../MySht2/MySht2?id=" + t + "&url=" + a + "&sessin=" + e + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName + "&url2=" + this.data.url2
        });
    },
    toIndex: function() {
        this.data.sessin == t.globalData.PHPSESSID ? wx.redirectTo({
            url: "../MyCenter/MyCenter?Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName
        }) : wx.switchTab({
            url: "../Draft/Draft"
        });
    },
    lastsave: function(t) {
        var a = this.data.obliga;
        a && this.setData({
            obliga2: a.join("")
        });
        var e = this.data.obliga2, i = this.data.parties, o = this.data.preface, n = this.data.title;
        wx.request({
            url: "http://localhost/wapcms/index.php?s=/addon/Contract/Contract/addContract",
            data: {
                obliga: e,
                parties: i,
                preface: o,
                title: n
            },
            method: "GET",
            header: {
                "Content-Type": "application/json"
            },
            success: function(t) {
                wx.redirectTo({
                    url: "../reviewask/reviewask"
                }), t && (wx.showToast({
                    title: "保存成功",
                    icon: "success",
                    duration: 2e3
                }), wx.removeStorage({
                    key: "obliga"
                }), wx.removeStorage({
                    key: "parties"
                }), wx.removeStorage({
                    key: "preface"
                }), wx.removeStorage({
                    key: "title"
                }));
            },
            fail: function(t) {
                t && wx.showToast({
                    title: "保存失败，请检查网络连接",
                    icon: "loading",
                    duration: 2600
                });
            }
        });
    },
    onShareAppMessage: function(t) {
        this.data.id, this.data.url;
        var a = this.data.sessin, e = this.data.Listurl, i = this.data.TopName;
        return {
            title: this.data.ht.title,
            path: "/pages/MySht/MySht?id=" + this.data.id + "&url=" + e + "ContractDetail&url2=" + e + "editContract&sessin=" + a + "&Listurl=" + e + "&TopName=" + i,
            success: function(t) {
                console.log(t);
            },
            fail: function(t) {}
        };
    },
    Operate: function() {
        var t = this;
        this.data.Listurl, this.data.From;
        wx.showActionSheet({
            itemList: [ "编辑合同", "委托审查合同", "只读模式", "发送至E-mail邮箱" ],
            success: function(a) {
                console.log(a.tapIndex), 0 == a.tapIndex && t.toEdit(), 1 == a.tapIndex && t.toExam(), 
                2 == a.tapIndex && t.noEdit(), 3 == a.tapIndex && t.CopytoPC();
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        });
    },
    toExam: function(t) {
        var a = this.data.Listurl;
        this.data.TopName;
        if ("Smcontract/Smcontract/" == a) e = "SM";
        if ("Wdraft/Wdraft/" == a) var e = "WT";
        var i = this.data.id;
        wx.navigateTo({
            url: "../../pages/ExamMy/ExamMy?id=" + i + "&htbase=" + e
        });
    },
    CopytoPC: function() {
        this.setData({
            condition: !1
        });
    },
    closeCluepage: function() {
        this.setData({
            condition: !0
        });
    },
    EmailSubmit: function(a) {
        console.log(a);
        var e = this, i = wx.getStorageSync("userInfo"), o = this.data.id, n = this.data.Listurl, s = a.detail.value.Email, l = this.Delplace(s), r = n + o, d = wx.getStorageSync(r) + parseInt(36e5);
        if (new Date().valueOf() <= d) wx.showModal({
            title: "提示",
            content: "您已经申请发送了该合同邮件，发送后须过1小时，方可就同一合同再次发送。如有急需，可联系客服。",
            showCancel: !1,
            success: function(t) {
                t.confirm || t.cancel;
            }
        }), this.setData({
            inputTxt: ""
        }); else {
            r = n + o;
            wx.removeStorageSync(r), (l.length <= 0 || !l) && wx.showToast({
                title: "未填写Email地址",
                icon: "loading",
                duration: 2e3
            }), l && l.length < 120 && (wx.showToast({
                title: "正在发送邮件",
                icon: "loading",
                duration: 2e4
            }), wx.request({
                url: t.url + "addon/" + n + "Mailsend",
                data: {
                    id: o,
                    Email: l,
                    nickName: i.nickName,
                    city: i.city
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    if (wx.hideToast(), 1 == t.data) {
                        e.setData({
                            inputTxt: ""
                        }), wx.showToast({
                            title: "提交发送成功",
                            icon: "success",
                            duration: 2e3
                        });
                        var a = n + o, i = new Date().valueOf();
                        wx.setStorageSync(a, i);
                    } else "timeout" == t.data ? (wx.showModal({
                        title: "提示",
                        content: "您已经申请发送了该合同邮件，发送后须过1小时，方可就同一合同再次发送。如有急需，可联系客服。",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                        }
                    }), e.setData({
                        inputTxt: ""
                    })) : (e.setData({
                        inputTxt: ""
                    }), "Todaytimeout" == t.data ? wx.showModal({
                        title: "提示",
                        content: "您今天已发送了超过20封合同邮件，投递员疲于往返，你也需要休息，明天再发可好？如有急需，可联系客服。",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                        }
                    }) : wx.showToast({
                        title: "发送邮件失败",
                        icon: "loading",
                        duration: 2200
                    }));
                },
                fail: function(t) {
                    wx.hideToast(), wx.showToast({
                        title: "无法连接网络",
                        icon: "loading",
                        duration: 2e3
                    }), e.setData({
                        inputTxt: ""
                    });
                }
            }));
        }
    },
    Delplace: function(t) {
        return t.replace(/(^\s*)|(\s*$)/g, "");
    }
});